#include <stdio.h>
 
int main(){
  
  int iX,iY;
  const int iXmax = 100; 
  const int iYmax = 100;
  unsigned char data[iYmax][iXmax]; /* 2D array for colors ( shades of gray ) */
  const int MaxColorComponentValue=255; /* color component is coded from 0 to 255 ;  it is 8 bit color file */
  FILE * fp;
  char *filename="n.pgm";
  char *comment="# this is my new binary pgm  file";/* comment should start with # */
 
  /* fill the data array */
  for(iY=0;iY<iYmax;++iY){  
    for(iX=0;iX<iXmax;++iX){ 
      data[iY][iX]=255;
    }
  }

 
/* write the whole data array to ppm file in one step */      
fp= fopen(filename,"wb"); /*create new file,give it a name and open it in binary mode  */
fprintf(fp,"P5\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);  /*write header to the file*/
fwrite(data,sizeof data,1,fp);  /*write image data bytes to the file*/
fclose(fp);
printf("OK - file %s saved\n", filename);
return 0;
}
